﻿Imports System.Data.OleDb
Public Class PhimDAO

    Public Function Insert(ByVal tmp As PhimDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into PHIM (TenPhim, GioiThieu, Trailer, Poster, ThoiLuong, NamSX, NuocSX, HangPhim) values (@TenPhim, @GioiThieu, @Trailer, @Poster, @ThoiLuong, @NamSX, @NuocSX, @HangPhim)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7, para8 As OleDbParameter
        para1 = New OleDbParameter("@TenPhim", tmp.TenPhim)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@GioiThieu", tmp.GioiThieu)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@Trailer", tmp.Trailer)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@Poster", tmp.Poster)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@ThoiLuong", tmp.ThoiLuong)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@NamSX", tmp.NamSX)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@NuocSX", tmp.NuocSX)
        cmd.Parameters.Add(para7)
        para8 = New OleDbParameter("@HangPhim", tmp.HangPhim)
        cmd.Parameters.Add(para8)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As PhimDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update PHIM set GioiThieu=@GioiThieu,Trailer=@Trailer,Poster=@Poster,ThoiLuong=@ThoiLuong,NamSX=@NamSX,NuocSX=@NuocSX,HangPhim=@HangPhim where TenPhim=@TenPhim"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7, para8 As OleDbParameter
        para1 = New OleDbParameter("@GioiThieu", tmp.GioiThieu)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@Trailer", tmp.Trailer)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@Poster", tmp.Poster)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@ThoiLuong", tmp.ThoiLuong)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@NamSX", tmp.NamSX)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@NuocSX", tmp.NuocSX)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@HangPhim", tmp.HangPhim)
        cmd.Parameters.Add(para7)
        para8 = New OleDbParameter("@TenPhim", tmp.TenPhim)
        cmd.Parameters.Add(para8)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As PhimDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from PHIM where TenPhim=@TenPhim"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@TenPhim", tmp.TenPhim)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function
    Public Function GetTable(ByVal t As String) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Public Function GetValue(ByVal t As String) As String
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim kq As String = cmd.ExecuteScalar()
        Return kq
    End Function
End Class
